In WPF we can use Label control to show some messages to user such as result of calculation price of certain things, to show caption etc. We can use XAML <Label /> element to create a Label control in WPF. In this demonstration I will show you how to use Label control in WPF.
The following code snippets represent use of Label control in WPF
<Label x:Name="lblMessage" Content="Hello Dear! Welcome to the demonstration of Label control" VerticalAlignment="Center" HorizontalAlignment="Center" />
Output of the following code snippet is as follows
Changing Foreground and Background of a Label control
The following code snippet changes the foreground and background of label control.
<Label x:Name="lblMessage" Content="Hello Dear! Welcome to the demonstration of Label control" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Aquamarine" Foreground="Blue" />
Out of the following code snippet is as follows
Applying style to a label control
<Label x:Name="lblMessage" Content="Hello Dear! Welcome to the demonstration of Label control" VerticalAlignment="Center" HorizontalAlignment="Center">
<Label.Foreground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.325" />
<GradientStop Color="#A0C30030" Offset="0.52" />
</LinearGradientBrush>
</Label.Foreground>
<Label.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="1" />
<GradientStop Color="#9B52A03D" Offset="0.455" />
</LinearGradientBrush>
</Label.Background>
</Label>
The output of the following code snippet is as follows
Anonymous User
15-Jul-2019Thanks for sharing.